import 'package:fate_blind_box/utils/default/common_config.dart';
import 'package:flutter/material.dart';
import '../../../theme/theme_color.dart';
import '../../main/model/shop_matchmaker_list_model.dart';
import 'package:amap_flutter_base/amap_flutter_base.dart';
import 'package:get/get.dart';
import 'map_navgation_utils.dart';
import 'near_by_map_view/match_shop_detail_page.dart';
import 'dart:io';

class CustomShareView {
  String distanceStr = '';
  double itemHeight = 60;

  showShareView(BuildContext context,
      {ShopMatchMakerListDataModel? dataModel,
      LatLng? locationPoint,
      String? saddress}) {
    dataModel??=ShopMatchMakerListDataModel();
    final size = MediaQuery.of(context).size;
    distanceStr = dataModel.distance??'';
    showModalBottomSheet(
        context: context,
        backgroundColor: Colors.white.withAlpha(0),
        elevation: 2,
        builder: (BuildContext context) {
          return SingleChildScrollView(
            child: Container(
              width: size.width,
              height: 220,
              padding: const EdgeInsets.only(bottom: 0, left: 0, right: 0),
              color: Colors.white,
              child: Column(
                children: [
                  const SizedBox(
                    height: 20,
                  ),
                  GestureDetector(
                    onTap: () {
                      Navigator.pop(context);
                      Get.to(MatchShopDetailPage(
                        detailModel: dataModel,
                        disStr: distanceStr,
                      ));
                    },
                    child: Container(
                      color: Colors.white,
                      margin: const EdgeInsets.only(left: 17),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Row(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Row(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    ClipRRect(
                                      child: dataModel!.matchPhoto != null
                                          ? Image.network(
                                              dataModel.matchPhoto ?? '',
                                              width: 50,
                                            )
                                          : Image.asset(
                                              "images/ic_canting.png",
                                              width: 50,
                                              height: 50,
                                              fit: BoxFit.cover,
                                            ),
                                    ),
                                    Column(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      children: [
                                        Row(
                                          children: [
                                            const SizedBox(
                                              width: 8,
                                            ),
                                            SizedBox(
                                              width: 200,
                                              child: Text(
                                                dataModel.shortName ?? '',
                                                style: TextStyle(
                                                    fontSize: 16,
                                                    color: ThemeColor.textColor,
                                                    overflow:
                                                        TextOverflow.ellipsis),
                                              ),
                                            )
                                          ],
                                        ),
                                        const SizedBox(
                                          height: 5,
                                        ),
                                        Row(
                                          children: [
                                            const SizedBox(
                                              width: 8,
                                            ),
                                            const SizedBox(
                                              width: 5,
                                            ),
                                            Text(
                                              distanceStr,
                                              style: TextStyle(
                                                  fontSize: 14,
                                                  color: ThemeColor
                                                      .textColorSecond,
                                                  overflow:
                                                      TextOverflow.ellipsis),
                                            ),
                                            const SizedBox(
                                              width: 3,
                                            ),
                                          ],
                                        )
                                      ],
                                    )
                                  ]),
                            ],
                          ),
                        ],
                      ),
                    ),
                  ),
                  Visibility(
                    visible: CommonConfig.isShowPay(),
                    child: GestureDetector(
                        child: Container(
                          alignment: Alignment.center,
                          margin: const EdgeInsets.fromLTRB(10, 20, 10, 0),
                          padding: const EdgeInsets.symmetric(vertical: 10),
                          height: 45,
                          // width: size.width -80,
                          decoration: ShapeDecoration(
                            shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(22.5)),
                            color: const Color(0xFF7F69D9),
                          ),

                          child: const Text(
                            '到这去',
                            style: TextStyle(color: Colors.white, fontSize: 16),
                          ),
                        ),
                        onTap: () {
                          Navigator.pop(context);
                          showModalBottomSheet(
                            context: context,
                            builder: (BuildContext context) {
                              String mapStr = Platform.isIOS ? '苹果地图' : '腾讯地图';
                              return SizedBox(
                                  height: 240.0,
                                  child: Container(
                                      alignment: Alignment.center,
                                      child: Column(
                                        children: [
                                          GestureDetector(
                                              onTap: () {
                                                if (Platform.isAndroid) {
                                                  MapNavUtils.gotoTencentMap(
                                                      dataModel!.latitude,
                                                      dataModel.longitude);
                                                } else {
                                                  MapNavUtils.gotoAppleMap(
                                                      dataModel!.latitude,
                                                      dataModel.longitude,
                                                      toAddress:
                                                          dataModel.address ??
                                                              '');
                                                }
                                              },
                                              child: Container(
                                                alignment: Alignment.center,
                                                width: size.width,
                                                height: itemHeight - 5,
                                                color: Colors.white,
                                                child: Text(mapStr),
                                              )),
                                          Divider(
                                            color: ThemeColor.sendMsgColor,
                                            height: 1,
                                          ),
                                          GestureDetector(
                                              onTap: () {
                                                MapNavUtils.gotoAMapByKeywords(
                                                    dataModel!.address,
                                                    dataModel.latitude,
                                                    dataModel.longitude,
                                                    locationPoint: locationPoint,
                                                    saddress: saddress);
                                              },
                                              child: Container(
                                                alignment: Alignment.center,
                                                width: size.width,
                                                height: itemHeight,
                                                color: Colors.white,
                                                child: const Text('高德地图'),
                                              )),
                                          Divider(
                                            color: ThemeColor.sendMsgColor,
                                            thickness: 7,
                                            height: 1,
                                          ),
                                          GestureDetector(
                                              onTap: () {
                                                MapNavUtils.gotoBaiduByKeywords(
                                                    dataModel!.address,
                                                    dataModel.latitude,
                                                    dataModel.longitude,
                                                    saddress: saddress ?? '',
                                                    slat: locationPoint!.latitude,
                                                    slon:
                                                        locationPoint.longitude);
                                              },
                                              child: Container(
                                                alignment: Alignment.center,
                                                width: size.width,
                                                height: itemHeight,
                                                color: Colors.white,
                                                child: const Text('百度地图'),
                                              )),
                                          Divider(
                                            color: ThemeColor.sendMsgColor,
                                            thickness: 7,
                                            height: 1,
                                          ),
                                          GestureDetector(
                                              onTap: () {
                                                Navigator.pop(context);
                                              },
                                              child: Container(
                                                alignment: Alignment.center,
                                                width: size.width,
                                                height: 55,
                                                child: const Text('取消'),
                                              ))
                                        ],
                                      )));
                            },
                          );
                        }),
                  ),
                ],
              ),
            ),
          );
        });
  }

  static String calculateTwoPointDistance(LatLng point1, LatLng point2) {
    // 调用高德地图API计算距离
    double distance = AMapTools.distanceBetween(point1, point2);
    distance = distance / 500.0;
    String distanceStr = distance.toStringAsFixed(2);
    return distanceStr;
  }
}
